'use strict';

const BaseController = require('./base');

const Controller = require('egg').Controller;

class RoleController extends BaseController {

  // 添加角色
  async addRole() {
    const { ctx } = this;
    const postData = ctx.request.body;
    const result = await ctx.service.sys.role.addRole(postData);
    this.success(result);
  }

  // 获取角色
  async getRoles() {
    const { ctx } = this;
    const result = await ctx.service.sys.role.getRoles();
    this.success(result);
  }

  // 通过Id获取角色
  async getRole() {
    const { ctx, app } = this;
    const result = await ctx.service.sys.role.getRole(ctx.request.query.id);
    this.success(result);
  }

  // 更新角色
  async updateRole() {
    const { ctx } = this;
    const postData = ctx.request.body;
    const result = await ctx.service.sys.role.updateRole(postData);
    this.success(result);
  }

  // 删除角色
  async deleteRole() {
    const { ctx } = this;
    const result = await ctx.service.sys.role.deleteRole(ctx.query.id);
    this.success(result);
  }

}

module.exports = RoleController;
